import gtk
from pattern.circuit import Control

class entry(Control):

    VERBS = ["Create"]
    
    def realize(self, event):
        # Create window
        self.window = gtk.Window()
        self.window.show()
        self.widget = None

    def incoming(self, event):
        self.clean()
    
    def clean(self):
        if self.widget is not None:
            self.window.remove(self.widget)    
            self.widget = None

    def verb(self, event):
        bridge = self.acquireInterface(event, "child")
        if bridge is not None:
            bridge.frame.on["creating"] = self.on_create_child
            bridge.push()

    def on_create_child(self, event, widget):
        if widget.get_parent() is not None:
            widget.get_parent().remove(widget)
        self.clean()
        self.window.add(widget)
        self.widget = widget
        
    def x():
        # Create tree store
        self.treestore = gtk.TreeStore(str)
        hello = self.treestore.append(None, ["Hello"])
        self.treestore.append(hello, ["There"])
        self.treestore.append(hello, ["World"])
        # Create tree view
        self.treeview = gtk.TreeView(self.treestore)
        self.treeview.set_size_request(100, 100)
        self.window.add(self.treeview)
        # Create tree column
        self.treeview.append_column(gtk.TreeViewColumn("Word", gtk.CellRendererText(), text=0))
        # Show controls
        self.treeview.show()

    def shutdown(self, event):
        self.clean()
        self.window.destroy()
